#!/usr/bin/env bash


# 一键安装： curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

#https://docs.redis.com/latest/ri/installing/install-docker/
if [ `whoami` != "root" ];then
  echo "must be root"
  exit 1
fi

which "docker" > /dev/null
if [ $? -eq 0 ]
then
    echo "docker已安装"
    exit 1
fi

# sudo apt-get remove docker docker-engine docker.io containerd runc

echo "安装docker..."
mkdir -p /etc/docker

cat <<EOF > /etc/docker/daemon.json
{
"registry-mirrors":[
    "https://hub-mirror.c.163.com",
    "https://registry.aliyuncs.com"
],
"graph":"/var/lib/docker",
"insecure-registries":["localhost:8000"],
"features": { "buildkit": true }
}
EOF


sudo apt-get update

sudo apt-get install     ca-certificates     curl     gnupg    lsb-release

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io


echo "开机启动docker..."
systemctl enable docker


# 设置存储位置，需要提前执行以下命令
# mkdir -p /data/docker
# ln -s /data/docker /var/lib/docker
